package com.chentf.reggie.demo;

/**
 * @author chentengfei
 * @desc ...
 * @date 2023-03-16 14:54:30
 */
public class ReverseInt {

    public static int reverse(int x){
        int rev = 0;
        while(x != 0){
            if(rev < Integer.MIN_VALUE /10 || rev > Integer.MAX_VALUE /10){
                return 0;
            }
            int result = x % 10;
            x = x / 10;
            rev = rev * 10 + result;
        }
        return rev;
    }

    public static void main(String[] args) {
        System.out.println(reverse(987654321));
    }
}
